<?php

namespace App\Http\Middleware;

use App\Services\MenuService;
use Closure;
use Illuminate\Support\Facades\Auth;

/**
 * 后台用户认证
 * Class Admin
 * @package App\Http\Middleware
 */
class Admin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!Auth::guard('admin')->check()) {
            return redirect('/admin/login')->withErrors(['登录过期，请重新登录！']);
        }

        MenuService::setPageMenu();
        \View::share('uid', Auth::guard('admin')->user()->getAuthIdentifier());
        return $next($request);
    }
}
